﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HT.Data.DB;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Odbc;
namespace HT.Data.DB
{
  class DBManagerFactory
  {

    private DBManagerFactory()
    {

    }
    public static IDbConnection GetConnection(Util.DataProvider providerType)
    {
      IDbConnection iDbConnection = null;
      switch (providerType)
      {
        case Util.DataProvider.SqlServer:
          iDbConnection = new SqlConnection();
          break;
        case Util.DataProvider.OleDb:
          iDbConnection = new OleDbConnection();
          break;
        case Util.DataProvider.Odbc:
          iDbConnection = new OdbcConnection();
          break;

        default:
          return null;
      }
      return iDbConnection;
    }

    public static IDbCommand GetCommand(Util.DataProvider providerType)
    {
      switch (providerType)
      {
        case Util.DataProvider.SqlServer:
          return new SqlCommand();
        case Util.DataProvider.OleDb:
          return new OleDbCommand();
        case Util.DataProvider.Odbc:
          return new OdbcCommand();

        default:
          return null;
      }
    }

    public static IDbDataAdapter GetDataAdapter(Util.DataProvider providerType)
    {
      switch (providerType)
      {
        case Util.DataProvider.SqlServer:
          return new SqlDataAdapter();
        case Util.DataProvider.OleDb:
          return new OleDbDataAdapter();
        case Util.DataProvider.Odbc:
          return new OdbcDataAdapter();

        default:
          return null;
      }
    }

    public static IDbTransaction GetTransaction(Util.DataProvider providerType)
    {
      IDbConnection iDbConnection = GetConnection(providerType);
      IDbTransaction iDbTransaction = iDbConnection.BeginTransaction();
      return iDbTransaction;
    }

    public static IDataParameter GetParameter(Util.DataProvider providerType)
    {
      IDataParameter iDataParameter = null;
      switch (providerType)
      {
        case Util.DataProvider.SqlServer:
          iDataParameter = new SqlParameter();
          break;
        case Util.DataProvider.OleDb:
          iDataParameter = new OleDbParameter();
          break;
        case Util.DataProvider.Odbc:
          iDataParameter = new OdbcParameter();
          break;

        

      }
      return iDataParameter;
    }

    public static IDbDataParameter[] GetParameters(Util.DataProvider providerType, int paramsCount)
    {
      IDbDataParameter[] idbParams = new IDbDataParameter[paramsCount];

      switch (providerType)
      {
        case Util.DataProvider.SqlServer:
          for (int i = 0; i < paramsCount; ++i)
          {
            idbParams[i] = new SqlParameter();
          }
          break;
        case Util.DataProvider.OleDb:
          for (int i = 0; i < paramsCount; ++i)
          {
            idbParams[i] = new OleDbParameter();
          }
          break;
        case Util.DataProvider.Odbc:
          for (int i = 0; i < paramsCount; ++i)
          {
            idbParams[i] = new OdbcParameter();
          }
          break;

        default:
          idbParams = null;
          break;
      }
      return idbParams;
    }
  }
}

